import 'package:flutter/material.dart';

import 'widgets/alert_dialog.dart';
import 'widgets/align_demo.dart';
import 'widgets/animated_align_demo.dart';
import 'widgets/app_bar.dart';
import 'widgets/aspect_ratio.dart';
import 'widgets/auto_complete.dart';
import 'widgets/bottom_app_bar.dart';
import 'widgets/bottom_navigation_bar.dart';
import 'widgets/bottom_sheet.dart';
import 'widgets/card.dart';
import 'widgets/checkbox.dart';
import 'widgets/chip.dart';
import 'widgets/listview.dart';
import 'widgets/text_field.dart';
import 'widgets/time_picker.dart';
import 'widgets/tooltip.dart';
import 'widgets/wrap.dart';

class DemoPageItem {
  final String title;
  final Widget page;

  DemoPageItem({required this.title, required this.page});
}

List<DemoPageItem> list = [
  DemoPageItem(title: 'AlertDialogDemo', page: const AlertDialogDemo()),
  DemoPageItem(title: 'AlignDemo', page: const AlignDemo()),
  DemoPageItem(title: 'AnimatedAlign', page: const AnimatedAlignDemo()),
  DemoPageItem(title: 'AppBarDemo', page: const AppBarDemo()),
  DemoPageItem(title: 'AspectRatioDemo', page: const AspectRatioDemo()),
  DemoPageItem(title: 'AutocompleteDemo', page: const AutocompleteDemo()),
  DemoPageItem(title: 'BottomAppBarPage', page: const BottomAppBarPage()),
  DemoPageItem(title: 'BottomSheetPage', page: const BottomSheetPage()),
  DemoPageItem(title: 'BottomNavigationBarPage', page: const BottomNavigationBarPage()),
  DemoPageItem(title: 'CardPage', page: const CardPage()),
  DemoPageItem(title: 'CheckBoxPage', page: const CheckBoxPage()),
  DemoPageItem(title: 'ChipPage', page: const ChipPage()),
  DemoPageItem(title: 'WrapPage', page: const WrapPage()),
  DemoPageItem(title: 'TooltipPage', page: const TooltipPage()),
  DemoPageItem(title: 'TimePickerPage', page: const TimePickerPage()),
  DemoPageItem(title: 'TextFieldPage', page: const TextFieldPage()),
  DemoPageItem(title: 'ListViewPage', page: const ListViewPage()),
];

class WidgetDemo extends StatelessWidget {
  const WidgetDemo({super.key});

  List<Widget> _buildGridItem(context) {
    return List<Container>.generate(
        list.length,
        (index) => Container(
            width: 10,
            height: 10,
            alignment: Alignment.center,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(8),
                border: Border.all(width: 1, color: Colors.black54)),
            child: TextButton(
                onPressed: () {
                  Navigator.of(context).push(MaterialPageRoute(
                    builder: (context) => list[index].page,
                  ));
                },
                child: Text(
                  list[index].title,
                  style: const TextStyle(color: Colors.blue),
                ))));
  }

  Widget _buildGrid(context) {
    return GridView.count(
      primary: false,
      padding: const EdgeInsets.all(4.0),
      crossAxisSpacing: 10,
      mainAxisSpacing: 10,
      crossAxisCount: 3,
      children: _buildGridItem(context),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("组件介绍页面"),
      ),
      body: _buildGrid(context),
    );
  }
}
